package com.ringtheweb.web.interceptor;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.intercept.AroundInvoke;
import org.jboss.seam.annotations.intercept.Interceptor;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.MethodContextInterceptor;
import org.jboss.seam.intercept.AbstractInterceptor;
import org.jboss.seam.intercept.InvocationContext;

@SuppressWarnings("serial")
@Interceptor(stateless = true, within = MethodContextInterceptor.class)

/**
 * Interceptor that prevents MethodContextInterceptor invoke directly the method
 * and therefore bypass the BusinessProcessInterceptor in the interception chain
 */
public class JbpmHandlerInterceptor extends AbstractInterceptor{
	@AroundInvoke
	public Object aroundInvoke(InvocationContext ctx) throws Exception {		
		Component comp = getComponent();
		if (comp!=null){
			String name = comp.getName();
			Contexts.getMethodContext().set(name,null);
		}
		Object ret = ctx.proceed();		
		return ret;
	}

	@Override
	public boolean isInterceptorEnabled() {
		return true;
	}
}
